package app;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.*;
import java.util.Properties;

public class E821JDBCBasics {
    public static void main(String[] args) throws IOException {
	try {

	    Connection con = getConnection(); // DriverManager.getConnection("jdbc:derby:C:\\workspace\\CM");

	    Statement stmt = con.createStatement();

	    ResultSet rs = stmt
		    .executeQuery("SELECT name, charge FROM merchant");

	    while (rs.next()) {

		String nm = rs.getString("name");

		double p = rs.getDouble("charge");

		System.out.println(nm + "   " + p);
	    }

	    con.close();

	} catch (SQLException ex) {

	    System.out.println("Error " + ex.getMessage());
	}
    }

    public static Connection getConnection() throws IOException, SQLException {
	Connection conn = null;
	Properties props = new Properties();
	InputStreamReader in = new InputStreamReader(new FileInputStream(
		"appProperties.txt"), "UTF-8");
	props.load(in);
	in.close();

	String connString = props.getProperty("DBConnectionString");
	conn = DriverManager.getConnection(connString);
	return conn;
    }

}
